import formJs from "./regexDetail.js"; //新增弹框配置项
// import myCharts from "@/components/intelligentMaintenanceManage/temperatureHumidity/echarts.vue";
import TableData from "@/components/public/el-table"; //主页面列表
import echarts from "@/components/softFoundationManage/pileDataManage/echarts.vue"; //弹框form
import echarts1 from "@/components/softFoundationManage/pileDataManage/echarts1.vue"; //弹框form
import echarts2 from "@/components/softFoundationManage/pileDataManage/echarts2.vue"; //弹框form

//主页面列表
import publicForm from "@/components/public/el-form.vue"; //弹框form
import {
    getMixertimedataList, //详情

} from "@/api/request.js";

export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
        "pageStatus",


    ],
    data() {
        return {
            visible: "",
            title: null,
            loading: false,
            tableData: [],
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            queryCriteriaData: {}, //分页
            dialogHeight: null,
            formObj: formJs.formObj,
            isEdit: false,
            currntData: null,
            dataInfo: null,
            formData: {},
            currentDetail: null,
            types: null,
            typeData: [

                {
                    text: "曲线图",
                    show: true
                },
                {
                    text: "实时动画",
                    show: false
                },

            ],
            echartsData: null,
            current: null
        };
    },
    components: {
        publicForm,
        TableData,
        echarts,
        echarts1,
        echarts2
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        statusNum: {
            handler(newVal) {
                if (newVal) {
                    this.edit(newVal);
                }
            },
            immediate: true,
        },
        pageStatus: {
            // handler(newVal) {
            // if (newVal) {

            // }
            // },
            immediate: true,
        },

        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;

                    this.getDetail({
                        fId: newVal.fId
                    })

                }
            },

            immediate: true,
        },


    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
        this.btnShow = true
        if (this.statusNum == 7) { //查看
            this.btnShow = false
            this.formObj.map((item) => {
                item.disabled = true;
            });
        }
        this.getHeight();
    },
    methods: {

        changeType(e, index) {
            for (let i in this.typeData) {
                if (parseFloat(i) === index) {
                    this.typeData[i].show = true;
                    // checked = this.typeData[i].text;
                } else {
                    this.typeData[i].show = false;
                }
            }
            // this.checked = checked;

        },
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },

        closeDialog() {
            this.$emit("close");
        },

        edit() {
            this.formData = this.$options.data.call(this).formData;
        },

        // 详情
        getDetail(obj) {
            this.loading = true;
            getMixertimedataList(obj).then((res) => {
                if (res.errcode == 0) {
                    this.loading = false;
                    var data = res.data;
                    this.formData = data.mixingtimedata;
                    this.tableData = data.mixertimedataList;
                    this.current = this.tableData[0]
                    this.echartsData = data.mixertimedataList;
                    this.foreachFunction(this.tableData);

                } else {
                    this.$message.error("列表数据获取失败", res.msg);
                    this.loading = false;
                }
            });
        },
        foreachFunction(tableData) {
            var that = this;
            let i = 0;
            setInterval(() => {
                that.current = tableData[i];
                if (i == tableData.length - 1) {
                    i = 0;
                } else {
                    i++;
                }
            }, 1000)
        }
    },
};